<template>
  <div class="songs">
    <div class="content" v-if="songsList.length != 0">
      <el-table :data="songsList" stripe>
        <!-- <el-table-column type="expand"> </el-table-column> -->
        <el-table-column type="index" align="center" width="50px">
        </el-table-column>
        <el-table-column type="index" label="歌曲" width="700px">
          <template scope="{row}">
            <div class="img">
              <GlobalImageDeep
                :imgWidth="60"
                :imgHeight="60"
                :url="row.al.picUrl"
              />
              <div class="name">
                <div class="name_top">
                  <span @click="toSongDetailsPage(row.id)">
                    {{ row.name }}</span
                  >
                  <i
                    @click="toMvDetailsPage(row.mv)"
                    v-if="row.mv != 0"
                    class="iconfont icon-MV"
                  ></i>
                </div>
                <div class="name_bottom">
                  <span v-for="(biename, index) in row.alia" :key="index">{{
                    biename
                  }}</span>
                </div>
              </div>
              <!-- 一些按钮 -->
              <div class="songsList_item_info_bt">
                <div>
                  <i class="iconfont icon-bofang" title="播放"></i>
                </div>
                <div>
                  <i class="iconfont icon-tianjia" title="添加到歌单"></i>
                </div>
                <div>
                  <i
                    class="iconfont el-icon-download"
                    style="font-size: 22px"
                    title="下载"
                  ></i>
                </div>
                <div>
                  <i
                    class="iconfont icon-fenxiang"
                    style="font-size: 20px"
                    title="分享"
                  ></i>
                </div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="歌手" width="300px" show-overflow-tooltip>
          <template scope="{row}">
            <div class="author one_txt_cut">
              <span
                v-for="item in row.ar"
                :key="item.id"
                @click="toSingerDetailsPage(item.id)"
              >
                {{ item.name }}
              </span>
            </div>
          </template>
        </el-table-column>

        <el-table-column type="index" label="时长" width="150px">
          <template scope="{row}">
            <div class="dt">
              {{ formatDt(row.dt) }}
            </div>
          </template>
        </el-table-column>
      </el-table>

      <el-row type="flex" justify="center" style="padding-top: 20px">
        <el-pagination
          layout="total,sizes,prev, pager, next"
          :total="total"
          :page-size="queryInfo.limit"
          :page-sizes="[10, 20, 50, 100]"
          @current-change="paginationCurrentChange"
          @size-change="sizeChange"
          :current-page="currentPage"
          popper-class="select"
        >
        </el-pagination>
      </el-row>
    </div>
    <el-row v-else type="flex" justify="center" style="padding-top: 20px">
      <img
        src="../../../assets/images/loading.3708220b.gif"
        alt=""
        height="200"
        width="200"
      />
    </el-row>
  </div>
</template>

<script>
import _ from "lodash";
import { getSearch } from "../../../api/searchApi";
import moment from "moment";

export default {
  name: "songs",
  props: {
    search: {
      required: true,
      type: String,
    },
  },
  components: {},
  data() {
    return {
      songsList: [],
      queryInfo: {
        keywords: this.search,
        limit: 20,
        offset: 0,
        type: 1,
      },
      total: "",
      currentPage: 1,
    };
  },
  created() {
    this.getSearchMethod();
  },
  watch: {
    search(newValue) {
      if (newValue.length !== 0) {
        this.queryInfo = {
          keywords: this.search,
          limit: 20,
          offset: 0,
          type: 1,
        };
        this.total = 0;
        this.currentPage = 1;
        this.getSearchMethod();
      }
    },
  },
  methods: {
    async getSearchMethod() {
      let result = await getSearch(this.queryInfo);
      if (result.code === 200) {
        this.songsList = result.result.songs;
        this.total = result.result.songCount;
      }
    },
    paginationCurrentChange(newPage) {
      this.queryInfo.offset = (newPage - 1) * this.queryInfo.limit;
      this.currentPage = newPage;
      this.songsList = [];
      this.getSearchMethod();
      this.$utils.scrollTop(0, 200);
    },
    sizeChange(size) {
      this.songsList = [];
      this.queryInfo.limit = size;
      this.getSearchMethod();
    },
    formatDt(time) {
      return moment(time).format("mm:ss");
    },
    toSongDetailsPage(id) {
      this.$router.push(`/songDetails/${id}`);
    },
    toSingerDetailsPage(id) {
      this.$router.push(`/singerDetails/${id}`);
    },
    toMvDetailsPage(id) {
      this.$router.push(`/mvDetails/${id}`);
    },
    updateData() {},
  },
  computed: {},
};
</script>

<style lang="less" scoped>
.songs {
  .img {
    position: relative;
    display: flex;
    align-items: center;
    &:hover .songsList_item_info_bt {
      opacity: 1;
    }
    /deep/ .el-image img {
      border-radius: 8px;
    }

    .name {
      display: flex;
      flex-direction: column;
      padding-left: 20px;
      .name_top {
        span {
          cursor: pointer;
          margin-right: 6px;
          &:hover {
            color: @globalColor;
          }
        }
      }
      .icon-MV {
        font-size: 22px;
        padding: 5px;
        color: @globalColor;
        &:hover {
          box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
          cursor: pointer;
        }
      }
      span {
        font-size: 13px;
        color: #999999;
      }
    }
    .songsList_item_info_bt {
      display: flex;
      opacity: 0;
      position: absolute;
      right: 20px;
      > div {
        display: flex;
        align-items: center;
        justify-content: center;

        border-radius: 50%;
        width: 30px;
        height: 30px;
        color: #999999;
        &:hover {
          border: 1px solid @globalColor;
          color: @globalColor;
          cursor: pointer;
        }
      }
    }
  }
  .author {
    span {
      margin-right: 10px;
      &:hover {
        cursor: pointer;
        color: @globalColor;
      }
    }
  }
}
</style>
